/*
 * 文 件 名:  BLAStartUpServlet.java
 * 版    权:  isoftstone Technologies Co., Ltd. Copyright 2013-2023,  All rights reserved
 * 描    述:  <描述>
 * 修 改 人:  issuser
 * 修改时间:  2013-8-26
 * 跟踪单号:  <跟踪单号>
 * 修改单号:  <修改单号>
 * 修改内容:  <修改内容>
 */
package com.isoftstone.iot.city.common;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;

import com.isoftstone.services.dict.util.I18nJS;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.context.event.ContextStartedEvent;
import org.springframework.web.context.WebApplicationContext;
import org.springframework.web.context.support.WebApplicationContextUtils;

import com.isoftstone.services.base.event.UpdateCacheEvent;

/**
 * 启动类
 * 
 */
public class StartUpServlet extends HttpServlet
{
    
    private static final long serialVersionUID = -6601248664488577533L;
    
    private static final Logger log =
        LoggerFactory.getLogger(StartUpServlet.class);
    
    @Override
    public void init()
        throws ServletException
    {
        try
        {
            WebApplicationContext wac = WebApplicationContextUtils
                .getRequiredWebApplicationContext(getServletContext());
            
            wac.publishEvent(new UpdateCacheEvent(wac));
            wac.publishEvent(new ContextStartedEvent(wac));

            // 载入数据字典
            I18nJS.init();
        }
        catch (Exception e)
        {
            this.getServletContext().setAttribute("system-startup-failed",
                true);
            
            log.error("start up servlet error ", e);
            throw new ServletException();
        }
    }
}
